//package com.misty.common.config;
//
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.deser.LocalTimeDeserializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateSerializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
//import com.fasterxml.jackson.datatype.jsr310.ser.LocalTimeSerializer;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//
//import java.time.LocalDate;
//import java.time.LocalDateTime;
//import java.time.LocalTime;
//import java.time.format.DateTimeFormatter;
//
//@Configuration
//@Slf4j
//public class LocalDateTimeFormatConfig {
//    private static final String DEFAULT_DATE_TIME_PATTERN = "yyyy-MM-dd HH:mm:ss";
//    private static final String DEFAULT_DATE_PATTERN = "yyyy-MM-dd";
////    private static final String DEFAULT_TIME_PATTERN = "HH:mm:ss";
//    private static final String DEFAULT_TIME_PATTERN = "HH:mm";
//
//    @Bean("formatObjectMapper")
//    @Primary
//    public ObjectMapper objectMapper(){
//        ObjectMapper objectMapper = new ObjectMapper();
//        JavaTimeModule javaTimeModule = new JavaTimeModule();
//        javaTimeModule.addSerializer(LocalDateTime.class, new LocalDateTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
//        javaTimeModule.addSerializer(LocalDate.class, new LocalDateSerializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
//        javaTimeModule.addSerializer(LocalTime.class, new LocalTimeSerializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
//        javaTimeModule.addDeserializer(LocalDateTime.class, new LocalDateTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_TIME_PATTERN)));
//        javaTimeModule.addDeserializer(LocalDate.class, new LocalDateDeserializer(DateTimeFormatter.ofPattern(DEFAULT_DATE_PATTERN)));
//        javaTimeModule.addDeserializer(LocalTime.class, new LocalTimeDeserializer(DateTimeFormatter.ofPattern(DEFAULT_TIME_PATTERN)));
//        objectMapper.registerModule(javaTimeModule);
//        return objectMapper;
//    }
//
////    @Bean
////    public Converter<String, LocalDateTime> localDateTimeConvert() {
////        return new Converter<String, LocalDateTime>() {
////            @Override
////            public LocalDateTime convert(String source) {
////                DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
////                LocalDateTime dateTime = null;
////                try {
////                    //2020-01-01 00:00:00
////                    switch (source.length()){
////                        case 10:
//////                            log.debug("传过来的是日期格式：{}",source);
////                            source=source+" 00:00:00";
////                            break;
////                        case 13:
//////                            log.debug("传过来的是日期 小时格式：{}",source);
////                            source=source+":00:00";
////                            break;
////                        case 16:
//////                            log.debug("传过来的是日期 小时:分钟格式：{}",source);
////                            source=source+":00";
////                            break;
////                    }
////                    dateTime = LocalDateTime.parse(source, df);
////                } catch (Exception e) {
////                    log.error(e.getMessage(),e);
////                }
////                return dateTime;
////            }
////        };
////    }
//}
